import Vue from 'vue'
import Router from 'vue-router'
import store from '../store/store'
import {
  lsWrite,
  lsRead
} from '../common/js/ls'
import * as types from '../store/type'
import Watermark from '@/common/js/watermark';
import Home from '../components/home.vue'


Vue.use(Router)
if (lsRead("user").userId) {
  store.commit(types.LOGIN, lsRead("user"));
}

window.onhashchange = function () {
  //console.log(location.hash)
}

export const staticRouter = [
  // {
  //   path: '/',
  //   meta: {
  //     watermark: false
  //   },
  //   component: () => import('@/components/index.vue')
  // },
  {
    path: '/child-log',
    name: 'Home',
    component: Home,
    children: [
      // 其他的路由都写到这里
      {
        path: 'logs',
        component: () => import('@/components/refuel')
      }
    ],
  },
  // {
  //   path: '/login',
  //   meta: {
  //     watermark: false
  //   },
  //   name: 'login',
  //   component: () => import('@/components/login.vue')
  // },
  // {
  //   path: '/refuel',
  //   name: 'refuel',
  //   component: () => import('@/components/layout/layout/'),
  //   children: [{
  //     path: "log",
  //     name: "log",
  //     component: () => import('@/components/refuel'),
  //   }, {
  //     path: 'station',
  //     name: 'station',
  //     component: () => import('@/components/gasStation')
  //   }],
  // },



]
export const router = new Router({
  //mode: 'history',
  //base: window.__POWERED_BY_QIANKUN__ ? '/map' : process.env.BASE_URL,
  scrollBehavior: () => ({
    y: 0
  }),
  routes: staticRouter
})


router.afterEach((to) => {
  if (store.state.user.license && to.meta.watermark != false) {
    Watermark.set(store.state.user.license);
  } else {
    Watermark.set("");
  }

});
